<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('服务2列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>名称：</label>
                            <input type="text" name="serName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:service2:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:service2:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:service2:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-info single disabled" onclick="approve()" shiro:hasPermission="system:service2:approve">
                <i class="fa fa-bell"></i> 审核
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:service2:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:service2:remove')}]];
    var approveFlag = [[${@permission.hasPermi('system:service2:approve')}]];
    var statusDatas = [[${@dict.getType('sys_appr_status')}]];
    var prefix = ctx + "system/service2";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "服务",
            sortName: "createTime",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'serId',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'serName',
                    title: '名称'
                },
                {
                    field: 'serDes',
                    title: '描述'
                },
                {
                    field: 'serStatus',
                    title: '状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'instrument.instName',
                    title: '仪器'
                },
                {
                    field: 'serviceType.svtypeName',
                    title: '服务类型'
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var edit = '<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.serId + '\')"><i class="fa fa-edit"></i>编辑</a> ';
                        var methodList = '<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.serId + '\')"><i class="fa fa-list"></i>方法列表</a> ';
                        var remove = '<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.serId + '\')"><i class="fa fa-remove"></i>删除</a>';
                        var approve = '<a class="btn btn-info btn-xs ' + approveFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.serId + '\')"><i class="fa fa-bell"></i>审核</a>';
                        if(row.serStatus != 2){
                            actions.push(edit);
                            actions.push(methodList);
                        }
                        if(row.serStatus != 0 && row.serStatus != 1 && row.serStatus != 6){
                            actions.push(approve);
                        }
                        actions.push(remove);
                        return actions.join(' ');
                    }
                }]
        };
        $.table.init(options);
    });

    /*方法列表-详细*/
    function detail(serId) {
        var url = prefix + '/methods/' + serId;
        $.modal.openTab("方法列表", url);
    }

    function approve(serId) {
        if($.common.isEmpty(serId)) {
            var status = $.table.selectColumns("serStatus");
            if(status == 0 || status == 1 || status == 6){
                $.modal.alertWarning("此状态无需审核");
            }else {
                $.modal.open("服务审核", prefix + "/approve?serId="+$.table.selectColumns("serId"));
            }
        }else {
            $.modal.open("服务审核", prefix + "/approve?serId="+serId);
        }
    }

</script>
</body>
</html>